package com.deep.deepenterprise.api.threadlocal;


import org.apache.commons.lang3.StringUtils;

/**
 * @Auth xyz
 * @Desc //TODO
 * @Time 14:41 2024/4/24
 */
public class DrLoginTokenContext {
    private static final ThreadLocal<String> USER_HOLDER = new ThreadLocal<>();

    /**
     * @Auth xyz
     * @Desc //TODO 存入userId
     * @Time 14:42 2024/4/24
     * @Param [token]
     */
    public static void setUserId(String userId) {
        USER_HOLDER.set(userId);
    }

    /**
     * @return java.lang.String
     * @Auth xyz
     * @Desc //TODO 获取userId
     * @Time 14:42 2024/4/24
     */
    public static String getUserId() {
        return USER_HOLDER.get();
    }

    /**
     * @Auth xyz
     * @Desc //TODO 清除UUID
     * @Time 14:42 2024/4/24
     */
    public static void remove() {
        USER_HOLDER.remove();
    }

    /**
     * @return boolean
     * @Auth xyz
     * @Desc //TODO 验证token是否存在
     * @Time 12:57 2024/4/22
     */
    public static boolean exists() {
        return StringUtils.isNotBlank(getUserId());
    }
}
